//package com.geese.module.security.core;
//
//import java.util.List;
//
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.security.core.GrantedAuthority;
//import org.springframework.security.core.authority.SimpleGrantedAuthority;
//import org.springframework.security.core.userdetails.UserDetails;
//import org.springframework.security.core.userdetails.UserDetailsService;
//import org.springframework.security.core.userdetails.UsernameNotFoundException;
//import org.springframework.stereotype.Service;
//
//import com.geese.common.entity.Account;
//import com.geese.common.entity.User;
//import com.geese.module.security.entity.Permission;
//import com.geese.module.security.service.PermissionService;
//import com.geese.module.user.dao.AccountMapper;
//import com.geese.module.user.dao.UserMapper;
//import com.geese.module.user.dto.UserDTO;
//import com.geese.module.user.model.SecurityUser;
//import com.geese.module.user.service.UserService;
//import com.google.common.collect.Lists;
//
///**
// * Created by Z先生 on 2017/2/21.
// */
////登录验证
//@Service
//public class MyUserDetailService implements UserDetailsService {
//
//    @Autowired
//    UserService userService;
//
//    @Autowired
//    private PermissionService permissionService;
//
//    @Autowired
//    private AccountMapper loginModelMapper;
//    @Autowired
//    private UserMapper userMapper;
//
//    @Override
//    public UserDetails loadUserByUsername(String account) {
//    	Account accountDO = loginModelMapper.findByAccount(account);
//    	if(accountDO == null || accountDO.getUserId() == null) {
//    		throw new UsernameNotFoundException("用户名或密码不正确");
//    	}
//        if (accountDO.getBlock() == 1) {
//        	throw new UsernameNotFoundException("你的账户已冻结,请联系客服");
//        }
//        List<Permission> permissions = permissionService.findByUserId(accountDO.getUserId());
//        List<GrantedAuthority> grantedAuthorities = Lists.newArrayList();
//        for (Permission permission : permissions) {
//            GrantedAuthority grantedAuthority = new SimpleGrantedAuthority(permission.getName());
//            grantedAuthorities.add(grantedAuthority);
//        }
//        
//        User userDO = userMapper.findById(accountDO.getUserId());
//        UserDTO userDto = new UserDTO();
//        userDto.setAccount(accountDO);
//        userDto.setId(userDO.getId());
//        userDto.setMobile(userDO.getMobile());
//        userDto.setUserName(userDO.getUsername());
//        userDto.setUserType(userDO.getUserType());
//        return SecurityUser.create(userDto, grantedAuthorities);
//    }
//
//
//}
